0970299de5
[xen.git] /
1 /* Excerpts written by Martin Mares <mj@atrey.karlin.mff.cuni.cz> */
2 /* Modified for i386/x86-64 Xen by Keir Fraser */
3
4 #include <xen/config.h>
5 #include <xen/cache.h>
6 #include <asm/page.h>
7 #include <asm/percpu.h>
8 #undef ENTRY
9 #undef ALIGN
10
11 #ifdef EFI
12
13 #define FORMAT "pei-x86-64"
14 #undef __XEN_VIRT_START
15 #define __XEN_VIRT_START __image_base__
16
17 ENTRY(efi_start)
18
19 #else /* !EFI */
20
21 #define FORMAT "elf64-x86-64"
22
23 ENTRY(start)
24
25 #endif /* EFI */
26
27 OUTPUT_FORMAT(FORMAT, FORMAT, FORMAT)
28
29 OUTPUT_ARCH(i386:x86-64)
30
31 PHDRS
32 {
33   text PT_LOAD ;
34 #if defined(BUILD_ID) && !defined(EFI)
35   note PT_NOTE ;
36 #endif
37 }
38 SECTIONS
39 {
40 #if !defined(EFI)
41   . = __XEN_VIRT_START;
42   __image_base__ = .;
43 #else
44   . = __image_base__;
45 #endif
46
47 #if 0
48 /*
49  * We don't really use this symbol anywhere, and the way it would get defined
50  * here would result in it having a negative (wrapped to huge positive)
51  * offset relative to the .text section. That, in turn, causes an assembler
52  * truncation warning when including all symbols in the symbol table for Live
53  * Patching code.
54  */
55   __2M_text_start = .;         /* Start of 2M superpages, mapped RX. */
56 #endif
57
58   . = __XEN_VIRT_START + MB(1);
59   _start = .;
60   .text : {
61         _stext = .;            /* Text and read-only data */
62        *(.text)
63        *(.text.cold)
64        *(.text.unlikely)
65        *(.fixup)
66        *(.text.kexec)
67        *(.gnu.warning)
68        _etext = .;             /* End of text section */
69   } :text = 0x9090
70
71 #ifdef EFI
72   . = ALIGN(MB(2));
73 #else
74   . = ALIGN(PAGE_SIZE);
75 #endif
76   __2M_text_end = .;
77
78   __2M_rodata_start = .;       /* Start of 2M superpages, mapped RO. */
79   .rodata : {
80        _srodata = .;
81        /* Bug frames table */
82        . = ALIGN(4);
83        __start_bug_frames = .;
84        *(.bug_frames.0)
85        __stop_bug_frames_0 = .;
86        *(.bug_frames.1)
87        __stop_bug_frames_1 = .;
88        *(.bug_frames.2)
89        __stop_bug_frames_2 = .;
90        *(.bug_frames.3)
91        __stop_bug_frames_3 = .;
92
93        *(.rodata)
94        *(.rodata.*)
95
96 #if defined(BUILD_ID) && defined(EFI)
97 /*
98  * No mechanism to put an PT_NOTE in the EFI file - so put
99  * it in .rodata section. (notes.o supplies us with .note.gnu.build-id).
100  */
101        . = ALIGN(4);
102        __note_gnu_build_id_start = .;
103        *(.note.gnu.build-id)
104        __note_gnu_build_id_end = .;
105 #endif
106        . = ALIGN(8);
107        /* Exception table */
108        __start___ex_table = .;
109        *(.ex_table)
110        __stop___ex_table = .;
111
112        /* Pre-exception table */
113        __start___pre_ex_table = .;
114        *(.ex_table.pre)
115        __stop___pre_ex_table = .;
116
117 #ifdef CONFIG_LOCK_PROFILE
118        . = ALIGN(POINTER_ALIGN);
119        __lock_profile_start = .;
120        *(.lockprofile.data)
121        __lock_profile_end = .;
122 #endif
123   } :text
124
125 #if defined(BUILD_ID) && !defined(EFI)
126 /*
127  * What a strange section name. The reason is that on ELF builds this section
128  * is extracted to notes.o (which then is ingested in the EFI file). But the
129  * compiler may want to inject other things in the .note which we don't care
130  * about - hence this unique name.
131  */
132   . = ALIGN(4);
133   .note.gnu.build-id : {
134        __note_gnu_build_id_start = .;
135        *(.note.gnu.build-id)
136        __note_gnu_build_id_end = .;
137   } :note :text
138 #endif
139   _erodata = .;
140
141 #ifdef EFI
142   . = ALIGN(MB(2));
143 #else
144   . = ALIGN(PAGE_SIZE);
145 #endif
146   __2M_rodata_end = .;
147
148   __2M_init_start = .;         /* Start of 2M superpages, mapped RWX (boot only). */
149   . = ALIGN(PAGE_SIZE);             /* Init code and data */
150   __init_begin = .;
151   .init.text : {
152        _sinittext = .;
153        *(.init.text)
154        /*
155         * Here are the replacement instructions. The linker sticks them
156         * as binary blobs. The .altinstructions has enough data to get
157         * the address and the length of them to patch the kernel safely.
158         */
159        *(.altinstr_replacement)
160        _einittext = .;
161   } :text
162   .init.data : {
163        *(.init.rodata)
164        *(.init.rodata.rel)
165        *(.init.rodata.str*)
166
167        . = ALIGN(POINTER_ALIGN);
168        __setup_start = .;
169        *(.init.setup)
170        __setup_end = .;
171
172        __initcall_start = .;
173        *(.initcallpresmp.init)
174        __presmp_initcall_end = .;
175        *(.initcall1.init)
176        __initcall_end = .;
177
178        *(.init.data)
179        *(.init.data.rel)
180        *(.init.data.rel.*)
181        . = ALIGN(4);
182        __trampoline_rel_start = .;
183        *(.trampoline_rel)
184        __trampoline_rel_stop = .;
185        __trampoline_seg_start = .;
186        *(.trampoline_seg)
187        __trampoline_seg_stop = .;
188        /*
189         * struct alt_inst entries. From the header (alternative.h):
190         * "Alternative instructions for different CPU types or capabilities"
191         * Think locking instructions on spinlocks.
192         */
193        . = ALIGN(8);
194         __alt_instructions = .;
195         *(.altinstructions)
196         __alt_instructions_end = .;
197
198        . = ALIGN(8);
199        __ctors_start = .;
200        *(.ctors)
201        __ctors_end = .;
202   } :text
203
204 #ifdef EFI
205   . = ALIGN(MB(2));
206 #else
207   . = ALIGN(PAGE_SIZE);
208 #endif
209   __init_end = .;
210   __2M_init_end = .;
211
212   __2M_rwdata_start = .;       /* Start of 2M superpages, mapped RW. */
213   . = ALIGN(SMP_CACHE_BYTES);
214   .data.read_mostly : {
215        *(.data.read_mostly)
216        . = ALIGN(8);
217        __start_schedulers_array = .;
218        *(.data.schedulers)
219        __end_schedulers_array = .;
220        *(.data.rel.ro)
221        *(.data.rel.ro.*)
222   } :text
223
224   .data : {                    /* Data */
225        . = ALIGN(PAGE_SIZE);
226        *(.data.page_aligned)
227        *(.data)
228        *(.data.rel)
229        *(.data.rel.*)
230        CONSTRUCTORS
231   } :text
232
233   .bss : {                     /* BSS */
234        . = ALIGN(STACK_SIZE);
235        __bss_start = .;
236        *(.bss.stack_aligned)
237        . = ALIGN(PAGE_SIZE);
238        *(.bss.page_aligned*)
239        *(.bss)
240        . = ALIGN(SMP_CACHE_BYTES);
241        __per_cpu_start = .;
242        *(.bss.percpu)
243        . = ALIGN(SMP_CACHE_BYTES);
244        *(.bss.percpu.read_mostly)
245        . = ALIGN(SMP_CACHE_BYTES);
246        __per_cpu_data_end = .;
247        __bss_end = .;
248   } :text
249   _end = . ;
250
251 #ifdef EFI
252   . = ALIGN(MB(2));
253 #else
254   . = ALIGN(PAGE_SIZE);
255 #endif
256   __2M_rwdata_end = .;
257
258 #ifdef EFI
259   . = ALIGN(4);
260   .reloc : {
261     *(.reloc)
262   } :text
263   /* Trick the linker into setting the image size to exactly 16Mb. */
264   . = ALIGN(__section_alignment__);
265   .pad : {
266     . = ALIGN(MB(16));
267   } :text
268 #else
269   efi = .;
270 #endif
271
272   /* Sections to be discarded */
273   /DISCARD/ : {
274        *(.exit.text)
275        *(.exit.data)
276        *(.exitcall.exit)
277        *(.discard)
278        *(.discard.*)
279        *(.eh_frame)
280 #ifdef EFI
281        *(.comment)
282        *(.comment.*)
283 #endif
284   }
285
286   /* Stabs debugging sections.  */
287   .stab 0 : { *(.stab) }
288   .stabstr 0 : { *(.stabstr) }
289   .stab.excl 0 : { *(.stab.excl) }
290   .stab.exclstr 0 : { *(.stab.exclstr) }
291   .stab.index 0 : { *(.stab.index) }
292   .stab.indexstr 0 : { *(.stab.indexstr) }
293   .comment 0 : { *(.comment) }
294 }
295
296 ASSERT(__image_base__ > XEN_VIRT_START ||
297        _end <= XEN_VIRT_END - NR_CPUS * PAGE_SIZE,
298        "Xen image overlaps stubs area")
299
300 #ifdef CONFIG_KEXEC
301 ASSERT(kexec_reloc_size - kexec_reloc <= PAGE_SIZE, "kexec_reloc is too large")
302 #endif
303
304 #ifdef EFI
305 ASSERT(IS_ALIGNED(__2M_text_end,     MB(2)), "__2M_text_end misaligned")
306 ASSERT(IS_ALIGNED(__2M_rodata_start, MB(2)), "__2M_rodata_start misaligned")
307 ASSERT(IS_ALIGNED(__2M_rodata_end,   MB(2)), "__2M_rodata_end misaligned")
308 ASSERT(IS_ALIGNED(__2M_init_start,   MB(2)), "__2M_init_start misaligned")
309 ASSERT(IS_ALIGNED(__2M_init_end,     MB(2)), "__2M_init_end misaligned")
310 ASSERT(IS_ALIGNED(__2M_rwdata_start, MB(2)), "__2M_rwdata_start misaligned")
311 ASSERT(IS_ALIGNED(__2M_rwdata_end,   MB(2)), "__2M_rwdata_end misaligned")
312 #else
313 ASSERT(IS_ALIGNED(__2M_text_end,     PAGE_SIZE), "__2M_text_end misaligned")
314 ASSERT(IS_ALIGNED(__2M_rodata_start, PAGE_SIZE), "__2M_rodata_start misaligned")
315 ASSERT(IS_ALIGNED(__2M_rodata_end,   PAGE_SIZE), "__2M_rodata_end misaligned")
316 ASSERT(IS_ALIGNED(__2M_init_start,   PAGE_SIZE), "__2M_init_start misaligned")
317 ASSERT(IS_ALIGNED(__2M_init_end,     PAGE_SIZE), "__2M_init_end misaligned")
318 ASSERT(IS_ALIGNED(__2M_rwdata_start, PAGE_SIZE), "__2M_rwdata_start misaligned")
319 ASSERT(IS_ALIGNED(__2M_rwdata_end,   PAGE_SIZE), "__2M_rwdata_end misaligned")
320 #endif
321
322 ASSERT(IS_ALIGNED(cpu0_stack, STACK_SIZE), "cpu0_stack misaligned")
323
324 ASSERT(IS_ALIGNED(__init_begin, PAGE_SIZE), "__init_begin misaligned")
325 ASSERT(IS_ALIGNED(__init_end,   PAGE_SIZE), "__init_end misaligned")
326
327 ASSERT(IS_ALIGNED(trampoline_start, 4), "trampoline_start misaligned")
328 ASSERT(IS_ALIGNED(trampoline_end,   4), "trampoline_end misaligned")
329 ASSERT(IS_ALIGNED(__bss_start,      4), "__bss_start misaligned")
330 ASSERT(IS_ALIGNED(__bss_end,        4), "__bss_end misaligned")